// 函数型的执行思想 createRouter,创建router实例对象 （new操作）
// createWebHistory 是两个函数 创建history模式的路由对象
import { createRouter, createWebHistory } from 'vue-router'
const Layout = () => import('@/views/Layout')
const Home = () => import('@/views/Home/index')
const PlayGround = () => import('@/views/PlayGround')
const TopCategory = () => import('@/views/category')
const SubCategory = () => import('@/views/category/sub.vue')
const Detail = () => import('@/views/Detail')
const Login = () => import('@/views/Login')
const routes = [
  {
    path: '/',
    name: 'layout',
    component: Layout,
    children: [
      {
        path: '',
        component: Home
      },
      // 顶级目录
      {
        name: 'category',
        path: 'category/:id',
        component: TopCategory
      },
      // 二级类目
      { path: 'category/sub/:id', component: SubCategory },
      // 商品详情
      { path: 'detail/:id', component: Detail }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/playground',
    name: 'playground',
    component: PlayGround
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL), // 路由模式切换需要调用方法
  routes
})

export default router
